package org.yanghaokun.quartz.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;
import org.yanghaokun.quartz.jobs.MainJob;
import org.yanghaokun.quartz.service.IQuartzService;
import org.yanghaokun.quartz.utils.QuartzJobInfo;
import org.yanghaokun.quartz.utils.QuartzUtils;

@Service
public class QuartzServiceImpl implements IQuartzService {
    //我们需要自动注入一个调度器的工厂
    @Autowired
    private SchedulerFactoryBean schedulerFactoryBean;
    @Override
    public void addJob(QuartzJobInfo info) {
        QuartzUtils.addJob(schedulerFactoryBean.getScheduler(),info.getJobName()
                , MainJob.class, info, info.getCronj());
    }

    @Override
    public void delJob(String jobName) {
        QuartzUtils.removeJob(schedulerFactoryBean.getScheduler(),jobName);
    }
}
